<?php
	require_once '../database/mysql/MysqlUserDao.php';
	
	use org\kahikai\database\mysql\MysqlUserDao;
	
	session_start();
	
	if(!isset($_SESSION['userDao'])) {
		$_SESSION['userDao'] = new MysqlUserDao();
	}
	
	$email = $_REQUEST['kahikai_user'];
	$_SESSION['user'] = $_SESSION['userDao']->getByEmail($email);
	if(!isset($_SESSION['user'])) {
		$_SESSION['isAuthenticated'] = false;
	} else {
		$_SESSION['isAuthenticated'] = (md5($_REQUEST['kahikai_password']) == $_SESSION['user']->password);
	}
	
	$source = $_SERVER['HTTP_REFERER'];
	header("location: $source");
?>